/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Jobs;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author sys9
 */
public class Jobsubmit extends HttpServlet {
   
   // Declarations here //
   
    JobsubmitDao jsd ;
    private boolean b;
    JobsubmitBean jbean;
    DateFormat dateFormat = new SimpleDateFormat("yyyy/mm/dd HH:mm:ss");
    java.util.Date date = new java.util.Date();
    private String todaysdate;
    private String rcheck;
    
    public Jobsubmit()
   {
        jbean = new JobsubmitBean();
                jsd = new JobsubmitDao();
   }

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            if (request.getParameter("Submit") != null)
            {
                System.out.println(" Submit button pressed");
            jbean.setTitle(request.getParameter("title"));
            jbean.setNum(request.getParameter("num"));
            jbean.setExp(request.getParameter("exp"));
            jbean.setQual(request.getParameter("qual"));
            jbean.setCname(request.getParameter("cname"));
            jbean.setContact(request.getParameter("contact"));
            jbean.setOrg(request.getParameter("org"));
            todaysdate = dateFormat.format(date);
            System.out.println("Current Date Time : " + todaysdate);
            jbean.setReg_date(todaysdate);
            b = jsd.insert(jbean);
          if (b == true)
          { 
            out.println("<script language = 'javascript'>alert('Insertion successfull'); location = 'Jobs/JobSubmit.jsp' </script>");
          }
          else
             out.println("<script language = 'javascript'>alert('Insertion Failed '); location = 'Jobs/JobSubmit.jsp' </script>");
        }
       // close button submit
       if (request.getParameter("Delete") != null)
        {
        System.out.println("Delete button pressed");
        rcheck = request.getParameter("rcheck");
        b = jsd.delete(rcheck);
        if (b ==true)
         out.println("<script language = 'javascript'>alert('Delete successfull'); location = 'Jobs/AdminJobsHome.jsp' </script>");
        else
            out.println("<script language = 'javascript'>alert('Delete Failed'); location = 'Jobs/AdminJobsHome.jsp' </script>");
       }

        }catch(Exception ex) {
            ex.printStackTrace();
        }
    } 

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    } 

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
